﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DeviceUnion
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen; 
            this.Text = string.Format("{0} - {1}", this.Text, Assembly.GetExecutingAssembly().GetName().Version.ToString());
            this.Load += MainForm_Load;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            LoadData();
            this.MiddlePanel.Controls.Clear();
            foreach (var item in FormDic)
            {
                var btn = new Button()
                {
                    Text = item.Key,
                    Tag = item.Value,
                    Dock = DockStyle.Top,
                    Height = 40,
                };
                btn.MouseClick += Btn_MouseClick;
                this.MiddlePanel.Controls.Add(btn);
            }
        }

        private void Btn_MouseClick(object sender, MouseEventArgs e)
        {
            if(e.Button!= MouseButtons.Left)
            {
                return;
            }
            var f = (sender as Button).Tag;
            if(f is Form)
            {
                var ff = f as Form;
                ff.ShowDialog();
            }
        }

        private Dictionary<string,Form> FormDic { get; set; }

        private void LoadData()
        {
            FormDic = new Dictionary<string, Form>();
            FormDic.Add("FFmpeg录屏", new FFmpeg.WinForm.FFmpegCapture());
            FormDic.Add("VLC视频播放器", new VLC.VLC_CaptureDesktop());
            FormDic.Add("语音测试", new Voice.VoiceTestForm() );
            FormDic.Add("二维码条形码测试", new QRCode.QRCodeForm());
            //FormDic.Add("摄像头测试", new FFmpeg.WinForm.FFmpegCapture());
        }

        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var af = new AboutForm();
            af.ShowDialog();
            af.Dispose();
        }
    }
}
